﻿using NBomber.CSharp;
using NBomber.Http.CSharp;

using var httpClient = new HttpClient();

var scenario = Scenario.Create("http_scenario", async context =>
{
    //var step1 = await Step.Run("order", context, async () =>
    //{
    //    var request = Http.CreateRequest("GET", "http://localhost:5218/order");
    //    var response = await Http.Send(httpClient, request);
    //    return Response.Ok();
    //});

    //var step2 = await Step.Run("product", context, async () =>
    //{
    //    var request = Http.CreateRequest("GET", "http://localhost:5218/product");
    //    var response = await Http.Send(httpClient, request);
    //    return Response.Ok();
    //});

    var step1 = await Step.Run("graphql", context, async () =>
    {
        var request = Http.CreateRequest("POST", "http://localhost:5099/graphql")
        .WithBody(new StringContent("{ \"query\":\"query{   order{    id    name    productId   }   product {     id     name     description   }}\",\"variables\":{}}", null, "application/json"));
        var response = await Http.Send(httpClient, request);
        return Response.Ok();
    });

    return Response.Ok();
})
.WithoutWarmUp()
.WithLoadSimulations(
    Simulation.Inject(rate: 1, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 50, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 100, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 300, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 400, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 500, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 600, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 700, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 800, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 900, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)),
    Simulation.Inject(rate: 1000, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30))
);

NBomberRunner
    .RegisterScenarios(scenario)
    .Run();